//package com.pubinfo.passbook.common.config;
//
//import com.googlecode.aviator.AviatorEvaluator;
//import com.googlecode.aviator.AviatorEvaluatorInstance;
//import com.googlecode.aviator.Options;
//import com.pubinfo.passbook.common.entity.TRuleFormula;
//import com.pubinfo.passbook.common.service.master.TRuleFormulaService;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.context.annotation.Bean;
//import org.springframework.context.annotation.Configuration;
//import org.springframework.util.CollectionUtils;
//
//import javax.annotation.Resource;
//import java.util.List;
//
//@Configuration
//public class AviatorEvaluatorConfig {
//  @Resource
//  TRuleFormulaService formulaService;
//
//  @Bean
//  public AviatorEvaluatorInstance aviatorEvaluatorInstance() {
//    // 创建解释器
//    AviatorEvaluatorInstance engine = AviatorEvaluator.newInstance();
//    // 打开跟踪执行
//    engine.setOption(Options.ALWAYS_PARSE_INTEGRAL_NUMBER_INTO_DECIMAL, true);
//    List<TRuleFormula> formulaList = formulaService.list();
//    if (!CollectionUtils.isEmpty(formulaList)) {
//      formulaList.stream().forEach(ruleFormula -> {
//        engine.compile(ruleFormula.getId(), ruleFormula.getFormula(), true);
//      });
//    }
//    //查询数据库，初始化所有表达式。
//    return engine;
//  }
//}
